package io.lkt.modules.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.lkt.common.utils.PageUtils;
import io.lkt.common.utils.Query;
import io.lkt.commons.dynamic.datasource.annotation.DataSource;
import io.lkt.modules.sys.dao.BArticleTempDao;
import io.lkt.modules.sys.dao.BArticleTempTypeDao;
import io.lkt.modules.sys.entity.BArticleTempTypeEntity;
import io.lkt.modules.sys.service.BArticleTempTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


@Service("bArticleTempTypeService")
public class BArticleTempTypeServiceImpl extends ServiceImpl<BArticleTempTypeDao, BArticleTempTypeEntity> implements BArticleTempTypeService {

    @Autowired
    BArticleTempDao bArticleTempDao;

    @Autowired
    BArticleTempTypeDao bArticleTempTypeDao;

    @Override
    @DataSource("master")
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<BArticleTempTypeEntity> page = this.page(
                new Query<BArticleTempTypeEntity>().getPage(params),
                new QueryWrapper<BArticleTempTypeEntity>()
                        .orderByDesc("order_num")
        );

        return new PageUtils(page);
    }

    @Override
    @DataSource("master")
    public List<BArticleTempTypeEntity> selectList() {
        QueryWrapper<BArticleTempTypeEntity> queryWrapper = new QueryWrapper();

        queryWrapper.eq("status", 1);
        queryWrapper.orderByDesc("order_num", "id");

        List<BArticleTempTypeEntity> list = bArticleTempTypeDao.selectList(queryWrapper);

        return list;
    }

    @Override
    @DataSource("master")
    public List<BArticleTempTypeEntity> getByName(String typeName) {
        QueryWrapper<BArticleTempTypeEntity> queryWrapper = new QueryWrapper();

        queryWrapper.eq("type_name", typeName);
        queryWrapper.eq("status", 1);

        List<BArticleTempTypeEntity> list = bArticleTempTypeDao.selectList(queryWrapper);

        return list;
    }

    @Override
    @DataSource("master")
    public BArticleTempTypeEntity getById(Integer id) {
        return bArticleTempTypeDao.selectById(id);
    }

    @Override
    @DataSource("master")
    public boolean save(BArticleTempTypeEntity entity) {
        return this.retBool(bArticleTempTypeDao.insert(entity));
    }

    @Override
    @DataSource("master")
    public boolean updateById(BArticleTempTypeEntity entity) {
        return this.retBool(bArticleTempTypeDao.updateById(entity));
    }

}
